fix(matrix): use adjoint_matrix for 3x3 inverse computation#14838
Open
maitriupadhyay03-cell wants to merge 7 commits into
Open
fix(matrix): use adjoint_matrix for 3x3 inverse computation#14838maitriupadhyay03-cell wants to merge 7 commits into
maitriupadhyay03-cell wants to merge 7 commits into
Conversation
…gorithms#7854) The split() function in treap.py uses `<` comparison but the docstring states that the right subtree should contain values "greater or equal" to the split value. This fix changes `elif value < root.value:` to `elif value <= root.value:` so that equal values go to the right subtree as documented. Fixes TheAlgorithms#7854
The 3x3 inverse computation had a bug: it was using cofactor_matrix instead of adjoint_matrix when seeding inverse_matrix (line ~148). The adjoint is correctly computed as the transpose of the cofactor matrix, but then discarded. This fix uses adjoint_matrix as required by the formula: inverse = (1/det) * adjoint. Also updates the 3x3 doctest to assert the correct inverse values. Fixes TheAlgorithms#14813
The inorder() function previously used print() to output values, which made its doctests thread-unsafe (pytest-run-parallel does not support doctests that use print). This fix: - Changes inorder() to return a comma-separated string instead of printing - Updates all interact_treap doctests to assert the returned string value - Adds a doctest to inorder() itself Fixes the CI failure: FAILED data_structures/binary_tree/treap.py::data_structures.binary_tree.treap.interact_treap
diusazzad
suggested changes
Jun 24, 2026
diusazzad
left a comment
There was a problem hiding this comment.
Hey @maitriupadhyay03-cell! 👋 Thanks for this fix. It looks like the tests are currently failing. Could you check the CI logs to see which test case is causing the error? If you need help debugging the logic, let me know!
Author
|
Hey @diusazzad, found the issue — the |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Describe your change:
Fixed a bug in
matrix/inverse_of_matrix.py— the 3x3 inverse was coming out wrong (it was returning the transpose of the actual inverse). Turned out the code was buildinginverse_matrixfromcofactor_matrixinstead ofadjoint_matrix, so the transpose step was getting skipped. One-line fix: useadjoint_matrixwhere it should've been all along. Also updated the doctest since it was asserting the wrong expected values.Fixes #14813
Checklist: